/*!
 * \file ast_dot_visitor.cc
 *
 * \brief Implementation of the Dot visitor for ast.
 *
 * \date Started: 7/12/2010
 * \date Last Modified: 7/27/2010
 * \authors Alan LaMielle
 * \authors Ian Craig
 * \authors Nicholas Jeanette
 *
 * Copyright (c) 2010, Colorado State University <br>
 * All rights reserved. <br>
 * See ../../COPYING for details. <br>
 */

#include <iegenlib/iegenlib.h>

namespace iegenlib{

/***************Dot Visitor**************/

//DotVisitor::DotVisitor(string inFst){
//  filestr.open(inFst.c_str());
//  count = 0;
//}

//void DotVisitor::PresFormIn(PresForm* node){
//   count = 0;
//}

void DotVisitor::defaultIn(Node* node){
  if(nodeStack.empty()){
    filestr << "digraph ASTGraph {" << endl;
  }

  filestr << count << " [label = \"" << node->getNodeType() << "\" ];" << endl;

  if(!nodeStack.empty()){
    filestr << nodeStack.top() << " -> " << this->count << endl;
  }

  nodeStack.push(count);
  count++;
}

void DotVisitor::defaultOut(Node* node){
  nodeStack.pop();
  if(nodeStack.empty()){
    filestr << "}" << endl;
//    filestr.flush();
//    filestr.close();
  }

}
/****************************************/
}//end namespace iegenlib
